<template src="./template.html"></template>

<style src="./style.css" scoped></style>
<script>
    import positionIcon from 'assets/images/position-icon.png';
    import navigator from 'utils/navigator';
    import route from 'constants/route';
    import constant from 'constants/constant';

    export default {
        data(){
            return {
                positionIcon: positionIcon,
                selectedIndex: 0,
                tabItems: [
                    {
                        index: 0,
                        title: '付款并开通免密支付',
                        selected: true,
                        titleColor: '#4d2805',
                        src: 'file://android_assets/www/newCash/signAndPay.js',
                        visibility: 'visible'
                    },
                    {
                        index: 1,
                        title: '付款',
                        selected: false,
                        titleColor: '#8d8d8d',
                        src: 'file://android_assets/www/cash/index.js',
                        visibility: 'hidden'
                    }]
            }
        },

        created(){
            let config = weex.config;

            /**开通免密支付参数*/
            let options_1 = {
                payMoney: config.payMoney,
                info: config.info,
                payId: config.payId,
                signType: config.signType,
                img: config.img,
                title: config.title,
                remark: config.remark
            }, options_2 = {
                payMoney: config.payMoney,
                payId: config.payId
            };

            // 参数转换
            this.tabItems[0].src += '?options=' + JSON.stringify(options_1);
            this.tabItems[1].src += '?options=' + JSON.stringify(options_2);

            this.$nextTick(()=>{
                this.select(this.selectedIndex);
            })
        },

        methods: {
            tabItemOnClick(tab){
                let _index = tab.index;
                this.selectedIndex = _index;

                this.select(_index);
            },

            select(index){
                this.selectedIndex = index;
                for (var i = 0; i < this.tabItems.length; i++) {
                    var tabItem = this.tabItems[i];
                    if (i == index) {
                        tabItem.selected = true;
                        tabItem.visibility = 'visible';
                    }
                    else {
                        tabItem.selected = false;
                        tabItem.visibility = 'hidden';
                    }
                }
            },

            change(e) { //slider 在改变的时候
                this.selectedIndex = e.index;
                this.select(e.index);
            },

            /**
             * 查看免密支付说明
             */
            goToSignMsg(){
                let config = weex.config;
                let options = {
                    classType: constant.Drawer_Class_Type,
                    url: route.security_pay_msg,
                    title: config.title + '说明',
                    params: {
                        info: config.info
                    }
                };
                navigator.push(options);
            }

        }
    }
</script>
